
@ARGV > 2 || die( "  require 3 args\n" ) ;

$title = $ARGV[0] ;

$fn_in = $ARGV[1] ;
    open( IN ,  '<' . $fn_in ) || die( "  input can't open :\n  $fn_in\n" ) ;
    binmode( IN ) ;

$fn_out = $ARGV[2] ;
    open( OUT ,  '>' . $fn_out ) || ( close( IN ) , die( "  output can't open :\n  $fn_out\n" ) ) ;
    binmode( OUT ) ;

$rotate = 0 ;
    $ct = "" ;
    while( <IN> ) {
        /[]]ct$/ && /^\s*[[]\s*-/ && ( $rotate = 1 ) ;
        /^snap_to_device(\s|$)/ && last ;
    }
    seek( IN , 0 , 0 ) ;

# A4: 595pt × 842pt
#     92%  -->  margin left + right  = 47pt  -->  left 32pt + right 15pt
#                      top  + bottom = 67pt  -->  top  42pt + title 10pt + bottom 15pt

$alt = join "\n" , (
    '/Times-Roman findfont 10 scalefont setfont' ,
    '42 800 moveto (' . $title . ') show' ,
    '32 15 translate' ,
    '0.92 0.92 scale' ,
    $rotate ? '-1 -1 scale -595 -842 translate' : () ,
    '' ,
) ;

# insert alt
    while( <IN> ) {
        print OUT $_ ;
        /^%%EndPageSetup/ && print OUT $alt ;
    }
    close( OUT ) ;
    close( IN ) ;
